#include <stdio.h>

#include "MPX_SUPT.H"
#include "COMMANDH.H"
#include "R3.h"
#include "R6.h"

#define CURRENT_MODULE MODULE_F

FILE *title_file;

int main()
{
	int sys_init_error; //used to grab error from sys_init
	int sys_set_vec_error;
	
	sys_init_error = sys_init(CURRENT_MODULE);
	if (sys_init_error) //if error exists, print message, otherwise, continue
		printf("There was a problem with sys_init, error #%d\0", sys_init_error);
	
	sys_set_vec_error = sys_set_vec(sys_call);
	if (sys_set_vec_error) //if error exists, print message, otherwise, continue
		printf("There was a problem with sys_set_vec, error #%d\0", sys_set_vec_error);
		
	//begin R6 additions
	
	//don't forget to change CURRENT_MODULE to MODULE_F-> mpx won't work after this change until io scheduler works
	//EDIT - the indented statements below are now handled in the init_iocbs call. we can change this if desired
		//call trm_open to open terminal (given on website)
		//call com_open to open com port (we wrote this in r5)
		//call others if needed- don't think so
	init_iocbs();//I wrote this in r3.c - sets up queues for both devices
	load_comhan();//helper routine I wrote in r6.c to create custom stack, etc and load as pcb
	load_idle();//helper routine I wrote in r6.c to load idle as a pcb
	//show_ready();//FOR TESTING ONLY//
	dispatch();//from r3, starts the continuous dispatch.  may want to run the ascii art first
	//I commented out the call to command handler below
	//close drivers after call to dispatch - only returns here once no processes left to dispatch
	mpx_io_cleanup();
		//note: command handler has to be made to kill itself and idle when exiting to get to this point
	//end with sys_exit
	
	//EDIT - moved ascii art reading to command handler function
	
	//end R6 additions
	
	//command_handler();
	
	//printf("\nThank you for using Team Adventure Time MPX\nPlease come again\0");
	sys_exit();
	return 0;
}